package com.smileymedia.util;

/**
 * Bit Utility for helpin us work with bits
 * @author greg
 *
 */
public class BitUtil {
	
	/**
	 * Unpack 32-bit integer into array of 4 bytes each component is 8 bits wide
	 * @param packed value
	 * @return byte[4] array of 4 unpacked components
	 */
	public static byte[] unpack(int packed) {
		byte[] bytes=new byte[4];
		bytes[0] = (byte) ((packed & 0xFF000000) >> 24) ;	
		bytes[1] = (byte) ((packed & 0x00FF0000) >> 16);
		bytes[2] = (byte) ((packed & 0x0000FF00) >> 8);
		bytes[3] = (byte) ((packed & 0x000000FF) >> 0);
		return bytes;
	}
	
	public static int pack(int v1, int v2,int v3, int v4) {
		return((v1 << 24) |  (v2 << 16) |  (v3 << 8) |   (v4&0xff << 0));
	}
	
}